package org.wiw.client.gui;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.DialogBox;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;

public class MessageDialog extends DialogBox {
	public enum Type {INFORMATION,WARNING,ERROR};
	
	private MessageDialog(String title, Widget w, Type type) {
		super();
		setText(title);
		setModal(true);
		
		VerticalPanel panel = new VerticalPanel();
		add(panel);
		
		if(type == Type.ERROR){
			w.addStyleName("dialogError");
		}
		
		panel.add(w);
		
		panel.add(
				new Button("Close" , 
						new ClickHandler() { public void onClick(ClickEvent event) { hide(); } }));
		
	}
	
	public static MessageDialog showDialog(String title, Widget w, Type type){
		MessageDialog messageDialog = new MessageDialog(title, w, type);
		messageDialog.center();
		return messageDialog;
	}
	

	public static MessageDialog showInformationDialog(String title, String message){
		return showDialog(title, new HTML(message), Type.INFORMATION);
	}
	
	public static MessageDialog showErrorDialog(String title, String message){
		return showDialog(title, new HTML(message), Type.ERROR);
	}
}
